package com.defysoft.waukids.calendar;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.defysoft.waukids.BaseFragment;
import com.defysoft.waukids.Data_Sharedpreferences;
import com.defysoft.waukids.Data_Type.WK_PROGRAM;
import com.defysoft.waukids.JsonParser;
import com.defysoft.waukids.PublicSharedpreferences;
import com.defysoft.waukids.R;
import com.defysoft.waukids.Sqlite_Connect;

public class Calendar_Main_Program extends BaseFragment implements OnClickListener{
	View view;
	boolean refresh=false;
	long now = System.currentTimeMillis();
	Date date = new Date(now);
	Sqlite_Connect sqlite_Connect;
	SimpleDateFormat mYear = new SimpleDateFormat("yyyy");
	SimpleDateFormat mMonth = new SimpleDateFormat("MM");
	SimpleDateFormat mDay = new SimpleDateFormat("dd");
	int year= Integer.parseInt(mYear.format(date))
			, month = Integer.parseInt(mMonth.format(date))
			, count, select_day;
	Calendar cal;
	ArrayList<String> mDayofNowMonth;
	TextView tv[] = new TextView[4];
	ListView lv;
	Calendar_Adapter adapter;
	Program_Adapter pro_adapter;
	GridView gv;
	Chinese_Date cd ;
	PublicSharedpreferences psf;
	Data_Sharedpreferences.SF_Member member;
	Data_Sharedpreferences.SF_Student student;
	ArrayList<WK_PROGRAM>program;
	ArrayList<WK_PROGRAM>pro_list;
	WK_PROGRAM pro;
	EditText input;
	EditText et;
	TextView tv_check[] = new TextView[2];
	RadioGroup rg;
	RadioButton radioButton;
	private final int SUCCESS = 10;
	private final int FAIL = 9;
	private final int NETWORK_ERR = 8;
	private final int CHANGE_SUCCESS = 7;
	private final int PROGRAM_LIST = 6;
	private final int DELETE_SUCCESS = 5;
	private final int WRITE_SUCCESS = 4;
	private final int EDIT_SUCCESS = 3;
	int pro_key=0;
	String student_code="",send_date="",choose_day="",subject="",pk_pro_code="",save_date="",pro_check="1";
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.calendar_main_fragment, null);	
		setStartData();
		
		return view;	
	}
	
	@Override
	public void setStartData() {
		super.setStartData();
		sqlite_Connect = new Sqlite_Connect(getActivity());
		gv = (GridView) view.findViewById(R.id.CALENDAR_MAIN_DATE);		
		tv[0] = (TextView) view.findViewById(R.id.CALENDAR_MAIN_TEXT);
		tv[1] = (TextView) view.findViewById(R.id.CALENDAR_PREV);
		tv[2] = (TextView) view.findViewById(R.id.CALENDAR_NEXT);
		tv[3] = (TextView) view.findViewById(R.id.CALENDAR_DATE);
		lv = (ListView) view.findViewById(R.id.CALENDAR_MAIN_LIST);
		cd = new Chinese_Date();
/*		// 년
		year = Integer.parseInt(mYear.format(date));
		// 월
		month = Integer.parseInt(mMonth.format(date));*/
		cal = Calendar.getInstance();
		cal.set(year, month - 1, 1);
		
		psf = new PublicSharedpreferences(getActivity());
		psf.setMembersp();
		member= psf.getMembersp(); 
		if(member.Rank.equals("3")){
		psf.setStudentsp();
		student = psf.getStudentsp();
		}
		pro_list = new ArrayList<WK_PROGRAM>();
		pro_adapter = new Program_Adapter();
		lv.setAdapter(pro_adapter);
		
		tv[1].setOnClickListener(this);
		tv[2].setOnClickListener(this);
		startNetwork(0);
	}
		//초기 달력 셋팅
	void addSchedule() {
		try {
			student_code= "";
			send_date =(cal.get(Calendar.MONTH)+1)+"";
			if(send_date.length()==2){
				send_date = (cal.get(Calendar.MONTH)+1)+"";
			}else{
				send_date = "0"+(cal.get(Calendar.MONTH)+1)+"";		
			}
			if(!member.Rank.equals("3")){
				student_code = "";
			}else{
				student_code=student.Code;
			}
			
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_CALENDAR_PROGRAM_LOAD
					+"&FK_Sch_Pro_Code=" + member.School
					+"&FK_Cla_Pro_Code=" + member.Class
					+"&Pro_Date=" + cal.get(Calendar.YEAR)+"-"+send_date
					+"&rank="+member.Rank
					));

			program = JsonParser.program_list(jsonObject.getString("payload"));
			
			if (jsonObject.getBoolean("success")) {
				onNetworkCallback(SUCCESS, "");
			} else {
				onNetworkCallback(FAIL, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(NETWORK_ERR, e.toString() + " where addSchedule()");
		}
	}
	
	void change_calender() {
		try {
			send_date =(cal.get(Calendar.MONTH)+1)+"";
			if(send_date.length()==2){
				send_date = (cal.get(Calendar.MONTH)+1)+"";
			}else{
				send_date = "0"+(cal.get(Calendar.MONTH)+1)+"";		
			}
			
			
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_CALENDAR_PROGRAM_LOAD
					+"&FK_Sch_Pro_Code=" + member.School
					+"&FK_Cla_Pro_Code=" + member.Class
					+"&Pro_Date=" + cal.get(Calendar.YEAR)+"-"+send_date
					+"&rank="+member.Rank
					));
			program = JsonParser.program_list(jsonObject.getString("payload"));
			
			if (jsonObject.getBoolean("success")) {
				onNetworkCallback(CHANGE_SUCCESS, "");
			} else {
				onNetworkCallback(FAIL, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(NETWORK_ERR, e.toString() + " where change_calender()");
		}
	}

	void pro_delete() {
			try{
			JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_CALENDAR_PROGRAM_DELETE
					+"&PK_Pro_Code=" + pro_list.get(pro_key).PK_Pro_Code
					));
			if (jsonObject.getBoolean("success")) {
				onNetworkCallback(DELETE_SUCCESS, jsonObject.getString("payload"));
			} else {
				onNetworkCallback(FAIL, jsonObject.getString("message"));
			}
		} catch (Exception e) {
			onNetworkCallback(NETWORK_ERR, e.toString()+ " where pro_delete()");
		}
	}
	
	void pro_write() {		
		try{JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_CALENDAR_PROGRAM_WRITE
					+"&Pro_Date="+ choose_day
					+"&FK_Sch_Pro_Code="+member.School
					+"&FK_Cla_Pro_Code="+member.Class
					+"&Pro_Check="+pro_check
					+"&rank="+member.Rank
					+"&subject="+subject));
		if (jsonObject.getBoolean("success")) {
			onNetworkCallback(WRITE_SUCCESS, jsonObject.getString("payload"));
		} else {
			onNetworkCallback(FAIL, jsonObject.getString("message"));
		}
	} catch (Exception e) {
		onNetworkCallback(NETWORK_ERR, e.toString()+ " where pro_write()");
	}
}
	
	void pro_edit() {		
		try{JSONObject jsonObject = new JSONObject(publicHttpCallback(HTTP_URL,
					"code=" + CODE_CALENDAR_PROGRAM_EDIT
					+"&PK_Pro_Code="+pro_list.get(pro_key).PK_Pro_Code
					+"&rank="+member.Rank
					+"&subject="+subject
					+"&Pro_Check="+pro_check));

		if (jsonObject.getBoolean("success")) {
			onNetworkCallback(EDIT_SUCCESS, jsonObject.getString("payload"));
		} else {
			onNetworkCallback(FAIL, jsonObject.getString("message"));
		}
	} catch (Exception e) {
		onNetworkCallback(NETWORK_ERR, e.toString() + " where pro_edit()" );
	}
}
	
	@Override
	public void startThread(int choice) {
		super.startThread(choice);
		final int cho = choice;
		firstThread  = new Thread(new Runnable() {	
			@Override
			public void run() {
				switch (cho) {
				case 0:
					addSchedule();
					break;		
				case 1:
					change_calender();
					break;
				case 2:
					pro_delete();
					break;
				case 3:
					pro_write();
					break;
				case 4:
					pro_edit();
					break;
				}
			}
		});
	
		firstThread.start();
		if(refresh==false){
		startDIal();
		}
	}
	
	@Override
	protected void handlingMessage(Message _message) {
		// TODO Auto-generated method stub
		super.handlingMessage(_message);
		switch (_message.what) {		
		case SUCCESS:	
			if (firstThread != null) {
				firstThread.interrupt();
			}
			//달력 셋팅
			Calendar_Grid(0);
			adapter = new Calendar_Adapter();
			gv.setAdapter(adapter);
			
			endDIal();
			break;
		
		case CHANGE_SUCCESS:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			adapter.notifyDataSetChanged();
			if(refresh==true){
				pro_list = new ArrayList<WK_PROGRAM>();
				for (int i = 0; i < program.size(); i++) {
						if(save_date.equals(program.get(i).Pro_Date)||choose_day.equals(program.get(i).Pro_Date)){
							pro = new WK_PROGRAM();
							pro.PK_Pro_Code = program.get(i).PK_Pro_Code;
							pro.FK_Sch_Pro_Code = program.get(i).FK_Sch_Pro_Code;
							pro.FK_Cla_Pro_Code = program.get(i).FK_Cla_Pro_Code;
							pro.Pro_Check = program.get(i).Pro_Check;
							pro.Pro_Date = program.get(i).Pro_Date;
							pro.Pro_Reason = program.get(i).Pro_Reason;
							pro_list.add(pro);					
						}
					}
			}
			pro_adapter.notifyDataSetChanged();
			endDIal();
			refresh = false;
			break;
			
		case PROGRAM_LIST:			
				pro_adapter.notifyDataSetChanged();		
			break;
			
		case DELETE_SUCCESS:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(getActivity(), (String) _message.obj, Toast.LENGTH_SHORT).show();
			endDIal();
			startNetwork(1);
			refresh = true;
			break;
		case WRITE_SUCCESS:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(getActivity(), (String) _message.obj, Toast.LENGTH_SHORT).show();
			endDIal();
			startNetwork(1);
			refresh = true;
			break;
		case EDIT_SUCCESS:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(getActivity(), (String) _message.obj, Toast.LENGTH_SHORT).show();
			endDIal();
			startNetwork(1);
			refresh = true;
			break;
		case FAIL:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			Toast.makeText(getActivity(), (String) _message.obj, Toast.LENGTH_SHORT).show();
			endDIal();
			break;
			
		case NETWORK_ERR:
			if (firstThread != null) {
				firstThread.interrupt();
			}
			sqlite_Connect.insert_Err_Log((String)_message.obj,android.os.Build.VERSION.SDK_INT,"Calendar_Main_Program", member.Email);
			endDIal();
			break;
		}
	}

	void Calendar_Grid(int count) {
		mDayofNowMonth = new ArrayList<String>();		
		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + count, 1);		
		tv[3].setText(cal.get(Calendar.YEAR)+"년-" +(cal.get(Calendar.MONTH)+1) + "월");
		
		int nNowMonthMaxDay = cal.getActualMaximum(Calendar.DATE);// 해당 달의 최대 날짜
		int nNowMonthStartWeek = cal.get(Calendar.DAY_OF_WEEK);// 해당 달 1일의 시작 위치

		// 앞의 빈공간 만들어줄 갯수
		int nDaysOfPrevMonth = 0;
		// 월요일로 시작되는 달이면
		if (nNowMonthStartWeek == 2) {
			nDaysOfPrevMonth = 1;
		}
		// 일요일로 시작되는 달이면
		else if (nNowMonthStartWeek == 1) {
			nDaysOfPrevMonth = 0;
		} else {
			nDaysOfPrevMonth = nNowMonthStartWeek - 1;
		}

		if (nDaysOfPrevMonth != 0) {
			for (int i = 0; i < nDaysOfPrevMonth; i++) {
				mDayofNowMonth.add("");
			}
		}

		for (int i = 0; i < nNowMonthMaxDay; i++) {
			mDayofNowMonth.add((i + 1) + "");
		}
		// 주
		int week = mDayofNowMonth.size() / 7;
		// 몇주 까지 있는지 계산
		week += mDayofNowMonth.size() % 7 != 0 ? 1 : 0;
		// 앞으로 남은 공백
		int mDayofAfterMonth = (week * 7) - mDayofNowMonth.size();// 공백 갯수
		// 어레이에 공백추가
		for (int i = 0; i < mDayofAfterMonth ; i++) {
			mDayofNowMonth.add("");
		}
			
	}

	class Calendar_Adapter extends ArrayAdapter<String> {

		public Calendar_Adapter() {
			super(getActivity(), android.R.layout.simple_list_item_1);
		}

		@Override
		public int getCount() {
			return mDayofNowMonth.size();
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Calendar_Holder holder;
		final int pos = position;
			if (convertView == null) {
				holder = new Calendar_Holder();
				convertView = getActivity().getLayoutInflater().inflate(
						R.layout.calendar_grid_row, null);
				holder.date = (TextView) convertView
						.findViewById(R.id.CALENDAR_ROW_TEXT);
				holder.ly = (LinearLayout)convertView.findViewById(R.id.CALENDAR_ROW_LL);
				holder.iv = (ImageView)convertView.findViewById(R.id.CALENDAR_ROW_CHECK);
				holder.ly_state = (LinearLayout)convertView.findViewById(R.id.CALENDAR_ROW_STATE);
				int width = ((gv.getWidth())/7);
				int height =(int)((double)(gv.getWidth()/7)*0.75);				
				holder.ly.setLayoutParams(new LinearLayout.LayoutParams(width,height));
				convertView.setTag(holder);
			} else {
				holder = (Calendar_Holder) convertView.getTag();
			}
			
			String day = mDayofNowMonth.get(position);
			if(day.length()<2){
				day ="0"+day;	
			}
						
			if(select_day == (position+1)){
				holder.ly.setBackgroundColor(0x778bc540);
				
			}else{
				holder.ly.setBackgroundColor(0xffffffff);
			}
			
			holder.date.setTextColor(0xff000000);
			holder.ly_state.setVisibility(View.GONE);
			cd.getHoliday((cal.get(Calendar.MONTH)+1));
			holder.iv.setVisibility(View.GONE);
			holder.date.setText(mDayofNowMonth.get(position));	
			
			if(!member.Rank.equals("3")){		
		holder.ly.setOnLongClickListener(new OnLongClickListener() {

				@Override
				public boolean onLongClick(View v) {
					select_day = (pos+1);
					String writeday =  mDayofNowMonth.get(pos);
					if(writeday.length()<2){
						writeday ="0"+writeday;	
					}
					choose_day= (cal.get(Calendar.YEAR)+"-"+send_date+"-"+writeday);
					if(member.Rank.equals("1")){
					dialog_rankone_write();
					}else if (member.Rank.equals("2")){
						dialog_ranktwo_write();
					}
					adapter.notifyDataSetChanged();
					return false;
				}
			});
					}
			
			holder.ly.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					select_day = (pos+1);
					String writeday =  mDayofNowMonth.get(pos);
					if(writeday.length()<2){
						writeday ="0"+writeday;	
					}
					pro_list = new ArrayList<WK_PROGRAM>();
				for (int i = 0; i < program.size(); i++) {
						if((cal.get(Calendar.YEAR)+"-"+send_date+"-"+writeday).equals(program.get(i).Pro_Date)){
							pro = new WK_PROGRAM();
							pro.PK_Pro_Code = program.get(i).PK_Pro_Code;
							pro.FK_Sch_Pro_Code = program.get(i).FK_Sch_Pro_Code;
							pro.FK_Cla_Pro_Code = program.get(i).FK_Cla_Pro_Code;
							pro.Pro_Check = program.get(i).Pro_Check;
							pro.Pro_Date = program.get(i).Pro_Date;
							pro.Pro_Reason = program.get(i).Pro_Reason;
							pro_list.add(pro);					
						}
					}
					onNetworkCallback(PROGRAM_LIST, "");
					adapter.notifyDataSetChanged();
				}
			});	
			
			if (position % 7 == 0) {
				holder.date.setTextColor(0xffff0000);
	
				}
			if (position % 7 == 6) {
				holder.date.setTextColor(0xff0066ff);

			}
			if (position % 7 == 6 || position % 7 == 0){
				holder.iv.setVisibility(View.GONE);
			}
			
			//일정 휴일
			for (int i = 0; i < program.size(); i++) {
			 if((cal.get(Calendar.YEAR)+"-"+send_date+"-"+day).equals(program.get(i).Pro_Date))
				if(program.get(i).Pro_Check.equals("1")){			
					holder.iv.setVisibility(View.GONE);
					holder.date.setText(mDayofNowMonth.get(position)+"\n"+program.get(i).Pro_Reason);
					holder.date.setTextColor(0xffff0000);
					holder.ly_state.setVisibility(View.VISIBLE);
					holder.ly_state.setBackgroundColor(0xff00cc00);
					break;
				}else{
					holder.iv.setVisibility(View.GONE);
					holder.ly_state.setVisibility(View.VISIBLE);
					holder.ly_state.setBackgroundColor(0xff00cc00);
				}
			}

			//휴일
			for (int j = 0; j < cd.date.size(); j++) {							
					if(mDayofNowMonth.get(position).equals(cd.date.get(j).day)){
						holder.date.setText(mDayofNowMonth.get(position)+"\n"+cd.date.get(j).name);
						holder.iv.setVisibility(View.GONE);
						holder.date.setTextColor(0xffff0000);
						holder.ly.setOnClickListener(null);
						holder.ly.setOnLongClickListener(null);
						break;
					}
				}

			return convertView;
		}
	}
	
	class Program_Adapter extends ArrayAdapter<String>{

		public Program_Adapter() {
			super(getActivity(), android.R.layout.simple_list_item_1);
			// TODO Auto-generated constructor stub
		}
		@Override
		public int getCount() {
		return pro_list.size();
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Pro_Holder pro_holder;
			final int pos = position;
		if(convertView==null){
			convertView = getActivity().getLayoutInflater().inflate(R.layout.calendar_beacon_list_row, null);
			pro_holder = new Pro_Holder();
			pro_holder.tv = (TextView)convertView.findViewById(R.id.CALENDAR_BEACONMSG_TV);
			pro_holder.tv_delete = (TextView)convertView.findViewById(R.id.CALENDAR_BEACONMSG_DELETE);
			pro_holder.tv_edit = (TextView)convertView.findViewById(R.id.CALENDAR_BEACONMSG_EDIT);
			convertView.setTag(pro_holder);
			}else{
				pro_holder = (Pro_Holder)convertView.getTag();
			}		
		if(member.Rank.equals("3")){
			pro_holder.tv_delete.setVisibility(View.GONE);
			pro_holder.tv_edit.setVisibility(View.GONE);
		}else if (member.Rank.equals("2")){
			if(pro_list.get(position).Pro_Check.equals("1")){
				pro_holder.tv_delete.setVisibility(View.GONE);
				pro_holder.tv_edit.setVisibility(View.GONE);
			}else{
			pro_holder.tv_delete.setVisibility(View.VISIBLE);
			pro_holder.tv_edit.setVisibility(View.VISIBLE);
			}
		}else{
			pro_holder.tv_delete.setVisibility(View.VISIBLE);
			pro_holder.tv_edit.setVisibility(View.VISIBLE);
		}
	
		pro_holder.tv.setText(pro_list.get(position).Pro_Date+"  "+pro_list.get(position).Pro_Reason);
		
		
		
			
		

		pro_holder.tv_delete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				pro_key = pos;
				pro_dialog_delete();

			}
		});
		
		
		pro_holder.tv_edit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				pro_key = pos;
				if(member.Rank.equals("1")){
					dialog_rankone_edit();
				}else{
						dialog_ranktwo_edit();
				}
			}
		});
			return convertView;
		}		
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.CALENDAR_NEXT:
			Calendar_Grid(+1);
			select_day=0;
			pro_list.clear();
			startNetwork(1);
			break;

		case R.id.CALENDAR_PREV:
			Calendar_Grid(-1);
			select_day=0;
			pro_list.clear();
			startNetwork(1);			
			break;
		
		case R.id.CALENDAR_DIALOG_NOMARL:
			tv_check[1].setBackgroundColor(0xffffcc66);
			tv_check[0].setBackgroundColor(0xffffffff);
			pro_check="2";
			break;
		case R.id.CALENDAR_DIALOG_HOLIDAY:
			tv_check[0].setBackgroundColor(0xffffcc66);
			tv_check[1].setBackgroundColor(0xffffffff);
			pro_check="1";
			break;
		}
	}
	
	class Calendar_Holder {
		TextView date;
		LinearLayout ly;
		LinearLayout ly_state;
		ImageView iv;
	}
	
	class Pro_Holder{
		TextView tv;
		TextView tv_delete;
		TextView tv_edit;
	}
	
	class Chinese_Date_Holder{
		String month;
		String day;
		String name;
	}
	
	class Chinese_Date {
		ArrayList<Chinese_Date_Holder> date;
		Chinese_Date_Holder cdh;
		ArrayList<Chinese_Date_Holder> getHoliday(int a) {
			date= new ArrayList<Chinese_Date_Holder>();			
			switch (a) {
			case 1:
				cdh = new Chinese_Date_Holder();
				cdh.month = "1";
				cdh.name = "신정";
				cdh.day ="1";
				date.add(cdh);
				break;
			case 3:
				cdh = new Chinese_Date_Holder();
				cdh.month = "3";
				cdh.name = "3.1절";
				cdh.day ="1";
				date.add(cdh);
				break;
			case 5:
				cdh = new Chinese_Date_Holder();
				cdh.month = "5";
				cdh.name = "어린이 날";
				cdh.day ="5";
				date.add(cdh);
				break;
			case 6:
				cdh = new Chinese_Date_Holder();
				cdh.month = "6";
				cdh.name = "현충일";
				cdh.day ="6";
				date.add(cdh);
				break;
			case 8:
				cdh = new Chinese_Date_Holder();
				cdh.month = "8";
				cdh.name = "광복절";
				cdh.day ="15";
				date.add(cdh);
				break;
			case 10:
				cdh = new Chinese_Date_Holder();
				cdh.month = "10";
				cdh.name = "개천절";
				cdh.day ="3";
				date.add(cdh);
				cdh = new Chinese_Date_Holder();
				cdh.month = "10";
				cdh.name = "한글날";
				cdh.day ="9";
				date.add(cdh);
				break;
			case 12:
				cdh = new Chinese_Date_Holder();
				cdh.month = "12";
				cdh.name = "크리스마스";
				cdh.day ="25";
				date.add(cdh);
				break;
			}
			return date;
		}
	}
	//원장선생님 일정등록
	void dialog_rankone_write(){
		AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
		alert.setTitle("일정 등록");
		alert.setMessage(choose_day+"일 일정 내용을 입력해주세요.");
		LayoutInflater inflater = getActivity().getLayoutInflater();
		View dia_ly =(View) inflater.inflate(R.layout.calendar_dialog_prowrite, null);
		
		et = (EditText)dia_ly.findViewById(R.id.CALENDAR_DIALOG_WRITE);
		tv_check[0] = (TextView)dia_ly.findViewById(R.id.CALENDAR_DIALOG_HOLIDAY);
		tv_check[1] = (TextView)dia_ly.findViewById(R.id.CALENDAR_DIALOG_NOMARL);
		
		alert.setView(dia_ly);	
		for (int i = 0; i < tv_check.length; i++) {
			tv_check[i].setOnClickListener(this);
		}
		alert.setPositiveButton("확인", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {	
				
				if(et.getText().toString().length()<1){		
					Toast.makeText(getActivity(), "일정을 입력하지 않으셨습니다. 다시 입력해주세요.",Toast.LENGTH_SHORT).show();
				}else{
				
					subject = et.getText().toString();
					startNetwork(3);	
				}
				
			}
		});

		alert.setNegativeButton("취소",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						// Canceled.
					}
				});
		
		alert.show(); 

	}
	//선생님 일정 등록
	void dialog_ranktwo_write(){
		AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
		alert.setTitle("일정 등록");
		alert.setMessage(choose_day+"일 일정 내용을 입력해주세요.");
		
		 input = new EditText(getActivity());		 
		 alert.setView(input);		 		 
		alert.setPositiveButton("확인", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				
				if(input.getText().toString().length()<1){
					Toast.makeText(getActivity(), "일정 입력하지 않으셨습니다. 다시 입력해주세요.",Toast.LENGTH_SHORT).show();
					
				}else{
					subject = input.getText().toString();
					startNetwork(3);	
				}
			}
		});

		alert.setNegativeButton("취소",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						// Canceled.
					}
				});
		
		alert.show(); 

	}
	
	void pro_dialog_delete(){
		AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
		alert.setTitle("삭제");
		
		
			alert.setMessage(pro_list.get(pro_key).Pro_Date+"일 "+pro_list.get(pro_key).Pro_Reason +" 일정을 삭제하시겠습니까?");
		
		
		alert.setPositiveButton("예", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				save_date = pro_list.get(pro_key).Pro_Date;
				startNetwork(2);	
				
			}
		});

		alert.setNegativeButton("아니오",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						// Canceled.
					}
				});		
		alert.show(); 
	}
	
	//선생님 일정 수정
		void dialog_ranktwo_edit(){
			AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
			alert.setTitle("일정 수정");
			alert.setMessage("수정할 내용을 입력해주세요.");
			
			 input = new EditText(getActivity());		 
			 alert.setView(input);
			 input.setText(pro_list.get(pro_key).Pro_Reason);
			 
			alert.setPositiveButton("확인", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					
					if(input.getText().toString().length()<1){
						Toast.makeText(getActivity(), "일정을 입력하지 않으셨습니다. 다시 입력해주세요.",Toast.LENGTH_SHORT).show();			
					}else{
						save_date = pro_list.get(pro_key).Pro_Date;
						subject = input.getText().toString();
						startNetwork(4);	
					}				
				}
			});
			
			alert.setNegativeButton("취소",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int whichButton) {
							// Canceled.
						}
					});
			
			alert.show(); 

		}
		
		//원장선생님 일정수정
		void dialog_rankone_edit(){
			AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
			alert.setTitle("일정 등록");
			alert.setMessage("수정할 내용을 입력해주세요.");
			LayoutInflater inflater = getActivity().getLayoutInflater();
			View dia_ly =(View) inflater.inflate(R.layout.calendar_dialog_prowrite, null);
			et = (EditText)dia_ly.findViewById(R.id.CALENDAR_DIALOG_WRITE);
			tv_check[0] = (TextView)dia_ly.findViewById(R.id.CALENDAR_DIALOG_HOLIDAY);
			tv_check[1] = (TextView)dia_ly.findViewById(R.id.CALENDAR_DIALOG_NOMARL);
			alert.setView(dia_ly);	
			
			pro_check = pro_list.get(pro_key).Pro_Check;
			
			for (int i = 0; i < tv_check.length; i++) {
				tv_check[i].setOnClickListener(this);
			}
			if(pro_list.get(pro_key).Pro_Check.equals("1")){
				tv_check[0].setBackgroundColor(0xffffcc66);
				tv_check[1].setBackgroundColor(0xffeeeeee);
			}else{
				tv_check[1].setBackgroundColor(0xffffcc66);
				tv_check[0].setBackgroundColor(0xffeeeeee);
			}
			et.setText(pro_list.get(pro_key).Pro_Reason);
			
			alert.setPositiveButton("확인", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {	
				
					if(et.getText().toString().length()<1){		
						Toast.makeText(getActivity(), "일정을 입력하지 않으셨습니다. 다시 입력해주세요.",Toast.LENGTH_SHORT).show();
					}else{
						save_date = pro_list.get(pro_key).Pro_Date;
						subject = et.getText().toString();
						startNetwork(4);	
					}
				}
			});

			alert.setNegativeButton("취소",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int whichButton) {
							// Canceled.
						}
					});
			alert.show(); 

		}
}
